﻿using System.Data;
using BookTheBook.Data.NameDefinitions;
using Migrator.Framework;

namespace BookTheBook.Migrations
{
    [Migration(3)]
    public class _003_NewTableRentDetails : Migration
    {
        public override void Up()
        {
            Database.AddTable(TableNames.RentDetails, 
                                    new Column(ColumnNames.RentDetailsId, DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
                                    new Column(ColumnNames.RentDate, DbType.Date, ColumnProperty.NotNull),
                                    new Column(ColumnNames.RentDays, DbType.Int16, ColumnProperty.NotNull),
                                    new Column(ColumnNames.UserId, DbType.Int32, ColumnProperty.NotNull));

            Database.AddForeignKey(ForeignKeyNames.UserToRentDetails, 
                                       TableNames.RentDetails, ColumnNames.UserId, 
                                       TableNames.User, ColumnNames.UserId);
        }

        public override void Down()
        {
            Database.RemoveForeignKey(TableNames.RentDetails, ForeignKeyNames.UserToRentDetails);
            Database.RemoveTable(TableNames.RentDetails);
        }
    }
}
